package com.ykyl.controller.security;


import com.ykyl.base.PageResponse;
import com.ykyl.base.Result;
import com.ykyl.pojo.dto.PostDto;
import com.ykyl.pojo.vo.PostVo;
import com.ykyl.service.PostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 岗位前端控制器
 */
@Slf4j
@RestController
@RequestMapping("post")
public class PostController {

    @Autowired
    PostService postService;

    /***
     *  多条件查询岗位分页列表
     * @param postDto 岗位Vo查询条件
     * @param pageNum 页码
     * @param pageSize 每页条数
     * @return: PageResponse<PostVo>
     */
    @PostMapping("page/{pageNum}/{pageSize}")
    public Result<PageResponse<PostVo>> findPostVoPageResponse(
                                    @RequestBody PostDto postDto,
                                    @PathVariable("pageNum") int pageNum,
                                    @PathVariable("pageSize") int pageSize) {
        PageResponse<PostVo> pageResponse = postService.findPostPage(postDto, pageNum, pageSize);
        return Result.success(pageResponse);
    }

    /**
     *  保存岗位
     * @param postDto 岗位DTO对象
     * @return PostDto
     */
    @PutMapping
    public Result<PostVo> createPost(@RequestBody PostDto postDto) {
        PostVo postVoResult = postService.createPost(postDto);
        return Result.success(postVoResult);
    }

    /**
     *  修改岗位
     * @param postDto 岗位DTO对象
     * @return Boolean 是否修改成功
     */
    @PatchMapping
    public Result<Boolean> updatePost(@RequestBody PostDto postDto) {
        Boolean flag = postService.updatePost(postDto);
        return Result.success(flag);
    }

    /**
     * 删除岗位
     */
    @DeleteMapping("/{postIds}")
    public Result remove(@PathVariable String[] postIds) {
        return Result.success(postService.deletePostByIds(postIds));
    }

    /***
     *  多条件查询岗位列表
     * @param postDto 岗位DTO对象
     * @return List<PostVo>
     */
    @PostMapping("list")
    public Result<List<PostVo>> postList(@RequestBody PostDto postDto) {
        List<PostVo> postVoList = postService.findPostList(postDto);
        return Result.success(postVoList);
    }


}
